package com.liangxw.site.user.controller;

import cn.hutool.json.JSONObject;
import com.liangxw.site.user.bean.User;
import com.liangxw.site.user.service.UserService;
import com.lxw.site.common.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;

/**
 * @Author xingwu
 * @Date 2021/1/9 15:39
 * @Version 1.0
 */
@RestController
@Scope(scopeName = "prototype")
@RequestMapping("user")
public class UserController {
    @GetMapping("test")
    public String test(){
        return "hello";
    }

    private int num = 1 ;//这样的成员变量在方法中修改 使用多例 最好

    @Autowired
    private UserService userService ;//单例还是多例都是一样的

    @GetMapping(value = "/id/{id}")
    private DataResult findUserList(@PathVariable("id") String id){
        return userService.findUserList(id);
    }

    /**
     * 用户登录
     * @param jsonStr
     * @return
     */
    @PostMapping("login")
    public DataResult userLogin(@RequestBody String jsonStr){
        System.out.println(num++);
        System.out.println("xxxxxxxxt热部署测试22xxxxxxxxx");
        JSONObject jsonObject = new JSONObject(jsonStr);
        String username =jsonObject.getStr("username");
        String password = jsonObject.getStr("password");
        System.out.println("接受到:");
        System.out.println(username);
        System.out.println(password);
        return userService.userLogin(username,password);
    }

    /**
     * 用户注册
     */


}
